package co.com.services.asignatura;

import javax.naming.NamingException;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import co.com.smart.maestro.infraestructure.dto.AsignaturaDTO;
import co.com.smart.session.DelegateContextEJB;

@Path("/SmartAsignaturaService")
public class AsignaturaService {
	@GET
	@Path("/getAllAsignatura")
	@Produces(MediaType.APPLICATION_JSON)
	public Response getAsignatura() throws NamingException{
		return Response.ok(DelegateContextEJB.getAsignaturaBeanLocal().consultarAllAsignatura())
		.header("Access-Control-Allow-Origin", "*")
		.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
		.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With").build();
	}
	
	@POST
	@Path("/getAsignaturaId")	
	@Produces(MediaType.APPLICATION_JSON)
	public Response getAsignaturaId(AsignaturaDTO json) throws NamingException {
		return Response.ok(DelegateContextEJB.getAsignaturaBeanLocal().consultarAsignaturaId(json))
		.header("Access-Control-Allow-Origin", "*")
		.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
		.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With").build();
	}

	@PUT
	@Path("/setAsignatura")
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	public Response setAsignatura( AsignaturaDTO json){ 
		return Response.ok(DelegateContextEJB.getAsignaturaBeanLocal().insertarAsignatura(json))
				.header("Access-Control-Allow-Origin", "*")
				.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
				.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With")
				.build();
	}

	@PUT
	@Path("/editAsignatura")
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	public Response setEditAsignatura(AsignaturaDTO json){ 
		return Response.ok(DelegateContextEJB.getAsignaturaBeanLocal().editAsignatura(json))
		.header("Access-Control-Allow-Origin", "*")
		.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
		.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With").build();
	}

	@PUT
	@Path("/removeAsignatura")
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	public Response setRemoveAsignatura(AsignaturaDTO json){ 
		return Response.ok(DelegateContextEJB.getAsignaturaBeanLocal().removeAsignatura(json, true))
				.header("Access-Control-Allow-Origin", "*")
				.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
				.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With").build();
	}
}